<template>
  <div class="echarts-wrap">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="12" :lg="12">
        <div class="chart echarts-bgcolor" ref="elChart1" ></div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="12">
        <div class="chart echarts-bgcolor" ref="elChart2"></div>
      </el-col>
    </el-row>
    <el-row :gutter="20" style="margin-top: 20px">
      <el-col :xs="24" :sm="24" :md="12" :lg="12">
        <div class="chart echarts-bgcolor" ref="elChart3"></div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="12">
        <div class="chart echarts-bgcolor" ref="elChart4"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { useEcharts } from '@/hooks/useEcharts'
import { onMounted, ref, nextTick } from 'vue'
import * as echarts from 'echarts'

const elChart1 = ref(null)
// const chart1 = useEcharts(elChart1)
const elChart2 = ref(null)
const chart2 = useEcharts(elChart2)
const elChart3 = ref(null)
const chart3 = useEcharts(elChart3)
const elChart4 = ref(null)
const chart4 = useEcharts(elChart4)

const options1 = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  legend: {
    data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: [
    {
      type: 'category',
      boundaryGap: false,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: 'Email',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [120, 132, 101, 134, 90, 230, 210]
    },
    {
      name: 'Union Ads',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [220, 182, 191, 234, 290, 330, 310]
    },
    {
      name: 'Video Ads',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [150, 232, 201, 154, 190, 330, 410]
    },
    {
      name: 'Direct',
      type: 'line',
      stack: 'Total',
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [320, 332, 301, 334, 390, 330, 320]
    },
    {
      name: 'Search Engine',
      type: 'line',
      stack: 'Total',
      label: {
        show: true,
        position: 'top'
      },
      areaStyle: {},
      emphasis: {
        focus: 'series'
      },
      data: [820, 932, 901, 934, 1290, 1330, 1320]
    }
  ]
}
const options2 = {
  polar: {
    radius: [30, '80%']
  },
  angleAxis: {
    max: 4,
    startAngle: 75
  },
  radiusAxis: {
    type: 'category',
    data: ['a', 'b', 'c', 'd']
  },
  tooltip: {},
  series: {
    type: 'bar',
    data: [2, 1.2, 2.4, 3.6],
    coordinateSystem: 'polar',
    label: {
      show: true,
      position: 'middle',
      formatter: '{b}: {c}'
    }
  }
}

const options3 = {
  xAxis: {
    data: ['2017-10-24', '2017-10-25', '2017-10-26', '2017-10-27']
  },
  yAxis: {},
  series: [
    {
      type: 'candlestick',
      data: [
        [20, 34, 10, 38],
        [40, 35, 30, 50],
        [31, 38, 33, 44],
        [38, 15, 5, 42]
      ]
    }
  ]
}
const options4 = {
  series: [
    {
      name: 'Pressure',
      type: 'gauge',
      progress: {
        show: true
      },
      detail: {
        valueAnimation: true,
        formatter: '{value}'
      },
      data: [
        {
          value: 50,
          name: 'SCORE'
        }
      ]
    }
  ]
}

onMounted(() => {
  nextTick(() => {
    const chart1 = echarts.init(elChart1.value)
    chart1.setOption(options1)
    // chart1.initChart(options1)
    chart2.initChart(options2)
    chart3.initChart(options3)
    chart4.initChart(options4)
  })
})

</script>

<style lang="scss" scoped>
  .echarts-wrap {
    .chart {
      width: 100%;
      height: 400px;
    }
  }
  .echarts-bgcolor {
    background-color: #eeeeee;
  }
</style>
